package com.bookshop.ui.customer;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;

import com.bookshop.logic.RemoteServiceAdapter;
import com.bookshop.ui.PageJumper;
import com.bookshop.ui.component.BasePagePanel;
import com.bookshop.ui.component.MyImageIcon;
import com.bookshop.ui.component.UIConstants;

public class CollectionPage extends BasePagePanel {
	public static class InvolvedData {
		public MyImageIcon image;
		public String id;
		public String name;
		public String publishDate;
		public String description;
		public String press;
		public String author;
		public String price;
	}

	private JPanel mBookBasePanel;
	
	public CollectionPage(PageJumper pJumper) {
		super(pJumper);
		init();
	}
	
	private void init() {
		mBookBasePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
		mBookBasePanel.setBackground(new Color(255, 255, 255));

		JScrollPane scrollPane = new JScrollPane(mBookBasePanel);
		scrollPane.setBounds(60, 86, 664, 436);
		add(scrollPane);
		reload();
	}

	@Override
	public void reload() {
		mBookBasePanel.removeAll();
		RemoteServiceAdapter adapter = RemoteServiceAdapter.instance();
		InvolvedData[] datas = adapter.showCollection(mJumper.getAccount());
		
		int length = datas.length;
		mBookBasePanel.setPreferredSize(new Dimension(577, (UIConstants.BOOKPANEL_HEIGHT + UIConstants.BOOKPANEL_VGAP) * length + 5));

		for(int i = 0; i < length; i++) {
			InvolvedData data = datas[i];
			JPanel child = new CollectionItemPanel(this, data);
			mBookBasePanel.add(child);
		}
		
		mBookBasePanel.validate();
		mBookBasePanel.repaint();
	}
}
